package com.geek.pokermanager.model;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import ydh.cicada.api.Column;
import ydh.cicada.api.Entity;
import ydh.cicada.api.Id;

@Entity(name="serializable_data")
public class SerializableData implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -7374811450172873409L;
	
	@Id
	@Column(name="serializable_data_id")
	private String serializableDataId;
	/**
	 * 房间id
	 */
	@Column(name="room_id")
	private String roomId;
	/**
	 * 分组数据
	 */
	@Column(name="group")
	private List<PokerGroup> group;
	
	private byte[] groupData;

	public String getRoomId() {
		return roomId;
	}

	public void setRoomId(String roomId) {
		this.roomId = roomId;
	}

	public List<PokerGroup> getGroup() {
		return group;
	}

	public void setGroup(List<PokerGroup> group) {
		this.group = group;
	}

	public String getSerializableDataId() {
		return serializableDataId;
	}

	public void setSerializableDataId(String serializableDataId) {
		this.serializableDataId = serializableDataId;
	}
	
	@SuppressWarnings("unchecked")
	public void setGroupByte(byte[] bytes) throws IOException, ClassNotFoundException {
		ByteArrayInputStream bais;  
        ObjectInputStream in = null;  
        try{  
            bais = new ByteArrayInputStream(bytes);  
            in = new ObjectInputStream(bais);  
            this.group = (List<PokerGroup>) in.readObject();
        }finally{  
            if(in != null){  
                try {  
                    in.close();  
                } catch (IOException e) {  
                    throw e;
                }  
            }  
        }  
	}
	
	public byte[] getGroupData() {
		return groupData;
	}

	public void setGroupData(byte[] groupData) throws ClassNotFoundException, IOException {
		setGroupByte(groupData);
	}

	
}
